We use “Using” keyword as directive in c#. “Using” keyword can be used for importing namespace to your classes.
Example:
Using System;
Using System.Data;
Another most useful advantage is it can be used in code blocks. It is called the “Dispose()” method automatically to release the resources and also automatically implements the try catch blocks for you. Here it is called a using statement. So the advantage is that we don’t have to explicitly write a try-catch block and our code looks small.
Syntax:
using ()
{
}
Example: Defines a scope, outside of which an object or objects will be disposed.
The object can be declared in the using statement, as shown above, or before the using statement as below
Font font = new Font("Times New Roman", 12.0f);
using (font)
{
// use font
}
Anonymous User
04-Jul-2019Nice Post.